package com.zhang.zxx.boot.config;

import com.zhang.zxx.boot.config.properties.MyKnife4jProperties;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * Knife4jConfiguration: Knife4j基本配置,这里结合maven和配置文件独立出来,保持项目一致
 *
 * @author zhangxiaoxiang
 * @date 2021年11月20日
 */
@Configuration
@EnableSwagger2WebMvc
@RequiredArgsConstructor
public class Knife4jConfiguration {

    private final MyKnife4jProperties c;

    @Bean(value = "defaultApi2")
    public Docket defaultApi2() {
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(new ApiInfoBuilder()
                        .title(c.getTitle()).description(c.getDescription()).termsOfServiceUrl("http://www.xx.com/")
                        .contact(new Contact(c.getName(), c.getUrl(), c.getEmail())).version(c.getVersion()).build())
                .groupName(c.getGroupName()).select().apis(RequestHandlerSelectors.basePackage(c.getBasePackage()))
                .paths(PathSelectors.any()).build();
    }
}